package org.example.reggie.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultData <T> implements Serializable {
    /**
     * 编码：1成功，0和其它数字为失败
     */
    private Integer code;
    /**
     * 提示信息
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;
    /**
     * 动态数据
     */
    private Map map = new HashMap();

    public static <T> ResultData<T> success(String msg,T object) {
        ResultData<T> r = new ResultData<T>();
        r.data = object;
        r.msg = msg;
        r.code = 1;
        return r;
    }
    public static <T> ResultData<T> success(T object) {
        ResultData<T> r = new ResultData<T>();
        r.data = object;
        r.code = 1;
        return r;
    }

    public static <T> ResultData<T> error(String msg) {
        ResultData r = new ResultData();
        r.msg = msg;
        r.code = 0;
        return r;
    }

    public ResultData<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }
}
